
/*
   用来定时开或者关其他的线程类，需要其他的线程类提供开关函数
   使用时，先用其他的线程类的开关函数注册该定时类。
*/
#include"timer.h"

using namespace std;

#define BUFF_LINE 512
#define BUFF_LINE_2 1024




Timer::Timer()
{
	this->t = chrono::seconds(0);
	this->is_running = NULL;
}

Timer::Timer( chrono::seconds time, CallbackFunc callbackFun)
{
	this->t = time;
	this->is_running = is_running;
	this->callbackFun = callbackFun;
}

Timer::~Timer()
{
}

void
Timer::scheduleRunningTime()
{
	this_thread::sleep_for( t );	
	this->callbackFun();
}


TimerThread::TimerThread( chrono::seconds(time), CallbackFunc callbackFunc )
{
	timer = Timer( time, callbackFunc);
}

TimerThread::TimerThread()
{
	timer = Timer();
}


TimerThread::~TimerThread()
{
	if(t_timer != NULL)
	{
		delete(t_timer);	
		t_timer=NULL;
	}
}

void
TimerThread::run_independent_timer()
{
	t_timer = new thread(&Timer::scheduleRunningTime, &timer );
	//t_timer->detach();
}
void
TimerThread::wait_for_timer()
{
	t_timer->join();
}

